<?php
    
	/**
	----------------------------------------------------------------------------------------
	If you are seeing this message in your web browser, it means PHP has not been setup
	or enabled on your web server. Enable PHP from your web hosting control panel or contact
	your web host to enable it for you.
	----------------------------------------------------------------------------------------
	*/
    
    require(dirname(__FILE__).'/init.php');
    
	$GLOBALS['template'] = "InlineHelp";
	
	define('AKB_WL_LANG_FILE',			dirname(__FILE__).'/includes/language/'.$GLOBALS['currentLanguage'].'/whitelabel.ini');
	define('AKB_LANG_FILE',				dirname(__FILE__).'/includes/language/'.$GLOBALS['currentLanguage'].'/front_language.ini');
	define('AKB_TPL_LOAD_PATH',			dirname(__FILE__).'/templates/'.$GLOBALS['template'].'/');
	define('AKB_TPL_PHP_PATH',			dirname(__FILE__).'/includes/display/');
	define('AKB_TPL_HTTP_PATH',			$GLOBALS['pathToKB'].'/templates/'.$GLOBALS['template'].'/');
	define('AKB_TPL_IMAGE_PATH',		AKB_TPL_HTTP_PATH.'Images');
	define('AKB_PANEL_LOAD_PATH',		AKB_TPL_LOAD_PATH.'Panels/');
	define('AKB_SNIPPET_LOAD_PATH',		AKB_TPL_LOAD_PATH.'Snippets/');
	define('CLASS_DIR', 				dirname(__FILE__).'/includes/classes');
	
	// Include the installation script so it can check if this system
	// has been installed or not and invoke the installer if required
	if ($GLOBALS['isSetup'] !== true) {
		header('Location: admin/');
		die();
	}

	require(CLASS_DIR.'/class.helper.php');
	require(CLASS_DIR.'/class.panel.php');
	require(CLASS_DIR.'/class.template.php');
	require(CLASS_DIR.'/class.auth.php');
	require(CLASS_DIR.'/class.index.php');

	$GLOBALS['AKB_CLASS_HELPER']	= new AKB_HELPER;
	$GLOBALS['AKB_CLASS_TEMPLATE']	= new AKB_TEMPLATE;
	$GLOBALS['AKB_CLASS_INDEX']		= new AKB_INDEX;

	$GLOBALS['SNIPPETS'] = '';
	if (!pageLoad()) {
		AKB_AUTH::ShowLoginForm(GetLang('SessionLoggedOutMessage'));
		die();
	}
	// Is the site down for maintenance?
	if ($GLOBALS['downForMaintenance'] == 1) {
		// Show the down for maintenance panel
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetPageTitle(GetLang('hpDownForMaintenance'));
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('Maintenance');
		$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
		die();
	}

	if (FrontendAccess()) {
		
		if ((isset($_GET['helpid'])) && ((int)$_GET['helpid'] > 0)) {
			$GLOBALS['HelpLink'] = GetUrl("question",(int)$_GET['helpid']);
		} else {
			$GLOBALS['HelpLink'] = GetUrl("category",(int)$_GET['searchOverride']);
		}
		
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('HelpContainer');
		$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
	} else {
		if (!isset($_POST['frontendPass'])) {
			$GLOBALS['HidePanels'] = array (
				'FrontendLoginError',
			);
		}
		$GLOBALS['FormAction'] = $GLOBALS['pathToKB'].'/index.php';
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetPageTitle(GetLang('kbLoginRequired'));
		$GLOBALS['AKB_CLASS_TEMPLATE']->SetTemplate('FrontendLogin');
		$GLOBALS['AKB_CLASS_TEMPLATE']->ParseTemplate();
	}

	// {{{ If debug is on, print the debug footer
	if (isset($GLOBALS['debug']) && $GLOBALS['debug'] == true) {
		$end_time = microtime_float();
		if (function_exists('memory_get_usage')) {
			$mem_used = memory_get_usage()/1024/1024;
		} else {
			$mem_used = 0;
		}
		printf('<div id="debug">Time taken to generate the page %.4f seconds and performed %d sql queries and used %.4f MB of memory</div>', ($end_time - $start_time), $GLOBALS['AKB_DB']->NumQueries, $mem_used);
	}
	// }}}
?>